<!--认款管理-->
<template>
  <div>
    <f-search-form :more='true' @searchHandler='searchHandler' :tableObj='$refs.table'>
      <f-search-form-item label='单位名称' name='customName' />
      <f-search-form-item label='单据编码' name='paymentNo' />
      <f-search-form-item label='单据日期' type='range' name='beginDate' />
    </f-search-form>
    <f-table ref='table' rowKey='paymentId' 
             :tableColumns='columns' 
             :showMultipleBtn='true' 
             :multiple='false' 
             :scroll='{x:true}' 
             :operator='operator' 
             :params='queryParam' 
             :api='api.payment' 
             handler='hyYfkTab2PageListHandler'>
      <span slot='fileList' slot-scope='text, record, index'>
        <f-images :value='record.fileList'></f-images>
      </span>
      <span slot='deptType' slot-scope='text'>
        <a-tag color='#2db7f5' v-if='text=="ZS"'>招商</a-tag>
        <a-tag v-if='text=="ZY"'>自营</a-tag>
      </span>
      <span slot='amountType' slot-scope='text, record, index'>
         <a-tag color='#87d068' v-if="text=='OrderAmount'">现款</a-tag>
         <a-tag color='#108ee9' v-if="text=='CustomBond'">资保金</a-tag>
         <a-tag color='#EE4B2B' v-if="text=='YfkAmount'">预收款</a-tag>
      </span>
      <span slot='paymentState' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==0'>未提交</a-tag>
            <a-tag color='#87d068' v-if='text==1' @click='processImg(record)'>{{ record.taskName }}</a-tag>
            <a-tag color='#EE4B2B' v-if='text==2'>已审批</a-tag>
       </span>
      <span slot='remitType' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==1'>普通转账</a-tag>
            <a-tag color='#108ee9' v-if='text==2'>电汇</a-tag>
            <a-tag color='#EE4B2B' v-if='text==3'>承兑</a-tag>
       </span>
      <span slot='action' slot-scope='text, record'>
          <template>
            <a @click='startProcess(record.paymentId,"hyAskAmountStartProcessHandler")' v-if='record.paymentState==0'>提交</a>
            <a @click='completeTask(record)' v-if="record.taskDefinitionKey&&record.taskDefinitionKey=='__initiator__' && record.paymentState!=0">提交</a>
            <a-divider type='vertical' v-if="record.paymentState==0 || record.taskDefinitionKey=='__initiator__'" />
            <a @click="$refs.drawer.showDrawer(record,'form1')" v-if="record.paymentState==0||record.taskDefinitionKey=='__initiator__'">编辑</a>
            <a-divider type='vertical' v-if="record.paymentState==0 ||record.taskDefinitionKey=='__initiator__'" />
            <a @click='openPaymentOrderModal(record)' v-if='record.amount>record.surplusAmount'>发货明细</a>
            <a-divider type='vertical' v-if='record.amount>record.surplusAmount && record.surplusAmount>0'></a-divider>
            <a-dropdown v-if='record.surplusAmount>0'>
            <a class='ant-dropdown-link'>更多<a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <!--认款审批通过显示-->
              <a-menu-item v-if='record.paymentState==2 && !record.refundId && record.surplusAmount>0'>
                  <a href='javascript:;' @click='$refs.refundDrawer.showDrawer({selectIds:record.paymentId,isAdd:true})'>退款</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
          </template>

        </span>
    </f-table>
    <amount-drawer ref='drawer' @success='searchHandler'></amount-drawer>
    <print-modal ref='printModal'></print-modal>
    <dikou-details-drawer ref='dikouDetailsDrawer'></dikou-details-drawer>
    <refund-drawer ref='refundDrawer'></refund-drawer>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
    <select-payment-order-modal ref='paymentOrderModal'></select-payment-order-modal>
  </div>
</template>
<script>
import AmountDrawer from "./components/amount_drawer.vue"
import api from "../js/api"
import PrintModal from "../print/print_modal"
import DikouDetailsDrawer from "@/views/module/haiying/salemanbalance/components/dikou_details_drawer"
import RefundDrawer from "@/views/module/haiying/custombalance/components/refund_drawer"
import { processMixins } from "@/core/mixins/processMixins"
import ProcessImage from "../../flowable/process/process_image"
import SelectPaymentOrderModal from "@/views/module/haiying/components/select_payment_order_modal"

export default {
  name: "Tab2",
  components: {
    SelectPaymentOrderModal,
    RefundDrawer,
    DikouDetailsDrawer,
    AmountDrawer,
    ProcessImage,
    PrintModal
  },
  mixins: [processMixins],
  data() {
    let me = this
    //操作按钮
    let operator = []
    return {
      api: Object.assign(api, this.api),
      processImageVisible: false,
      //列表初始化查询参数
      queryParam: {},
      multiple: true,
      // 表头
      columns: [
        {
          title: "序号",
          width: "60px",
          fixed: "left",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "认款单号",
          align: "left",
          fixed: "left",
          width: "120px",
          dataIndex: "paymentNo"
        },
        {
          title: "部门名称",
          align: "left",
          width: "150px",
          dataIndex: "deptName"
        },
        {
          title: "业务员",
          align: "left",
          width: "80px",
          dataIndex: "saleManName"
        },
        {
          title: "回款单位",
          align: "left",
          width: "120px",
          ellipsis: true,
          dataIndex: "payUserName"
        },
        {
          title: "回款金额",
          align: "left",
          width: "80px",
          dataIndex: "amount"
        },
        {
          title: "回款日期",
          align: "center",
          width: "100px",
          dataIndex: "amountDate"
        },
        {
          title: "收款银行",
          align: "left",
          width: "120px",
          ellipsis: true,
          dataIndex: "bankName"
        },
        {
          title: "汇款方式",
          align: "center",
          width: "80px",
          dataIndex: "remitType",
          scopedSlots: { customRender: "remitType" }
        },
        {
          title: "制单人",
          align: "center",
          width: "80px",
          dataIndex: "nickName"
        },
        {
          title: "备注",
          align: "center",
          width: "120px",
          ellipsis: true,
          dataIndex: "remark"
        },
        {
          title: "创建日期",
          align: "center",
          width: "120px",
          dataIndex: "createTime"
        },
        {
          title: "剩余金额",
          align: "left",
          width: "80px",
          fixed: "right",
          dataIndex: "surplusAmount"
        },
        {
          title: "审批状态",
          align: "left",
          dataIndex: "paymentState",
          fixed: "right",
          scopedSlots: { customRender: "paymentState" }
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "150px",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    //打开认款使用明细
    openPaymentOrderModal(record) {
      this.$refs.paymentOrderModal.open({
        paymentId: record.paymentId,
        amount: record.amount
      })
    },
    //打印单
    printPayment(paymentId) {
      this.$refs["printModal"].open(paymentId, 4, "YfkAmount")
    }
  }
}
</script>
